package com.ruoyi.web.controller.t;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.t.domain.TStyle;
import com.ruoyi.t.service.ITStyleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 款式Controller
 *
 * @author YY
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/t/style")
public class TStyleController extends BaseController
{
    @Autowired
    private ITStyleService tStyleService;

    /**
     * 查询款式列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TStyle tStyle)
    {
        startPage();
        List<TStyle> list = tStyleService.selectTStyleList(tStyle);
        return getDataTable(list);
    }

    /**
     * 导出款式列表
     */
    @Log(title = "款式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TStyle tStyle)
    {
        List<TStyle> list = tStyleService.selectTStyleList(tStyle);
        ExcelUtil<TStyle> util = new ExcelUtil<TStyle>(TStyle.class);
        util.exportExcel(response, list, "款式数据");
    }

    /**
     * 获取款式详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tStyleService.selectTStyleById(id));
    }

    /**
     * 新增款式
     */
    @Log(title = "款式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TStyle tStyle)
    {
        return toAjax(tStyleService.insertTStyle(tStyle));
    }

    /**
     * 修改款式
     */
    @PreAuthorize("@ss.hasPermi('t:style:edit')")
    @Log(title = "款式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStyle tStyle)
    {
        return toAjax(tStyleService.updateTStyle(tStyle));
    }

    /**
     * 删除款式
     */
    @Log(title = "款式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tStyleService.deleteTStyleByIds(ids));
    }
}
